home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / GETSTR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  700 b   |  24 lines

  1. /* getstr.c - get a line of input from keyboard */
  2. /* this is a subroutine function */
  3.  
  4. #include "stdio.h"
  5.  
  6. int getstr(s,maxs)        /* get a line of input */
  7.   char s[] ;            /* place the input here in string form */
  8.   int maxs ;            /* limit on characters allowed */
  9.   {                /* returns string length */
  10.     int i , c ;
  11.  
  12.     i = 0 ;
  13.     c = getchar() ;     /* get first character */
  14.                 /* repeat til full, EOF or end-of-line */
  15.     while(    (i < maxs) && (c != '\n') && ( c != EOF)  )
  16.       { s[i] = c ;        /* place char in string */
  17.         i = i + 1 ;     /* advance char count */
  18.         c = getchar() ;    /* and get another character */
  19.       }
  20.     s[i] = '\0'  ;
  21.     return( i )  ;        /* return count of characters */
  22.   }
  23.  
  24.